package com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.tag;

import cn.hutool.core.net.url.UrlBuilder;
import com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.IegProperties;
import com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.model.HutoolQuery;
import com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.model.HutoolRequest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * @author zgb
 * @desc ...
 * @date 2022-04-17 19:01:59
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@ConfigurationProperties(prefix = "ieg.tag")
public class IegTagProperties extends IegProperties {

    private String aiTagName;
    private HutoolRequest list;


    public String getListUrl(String name) {
        UrlBuilder urlBuilder = UrlBuilder.create().setScheme(super.getScheme()).setHost(super.getHost()).addPath(list.getPath());
        List<HutoolQuery> querys = list.getQuerys();
        for (HutoolQuery query : querys) {
            String key = query.getKey();
            String value = query.getValue();
            //要处理待赋值字段
            if (Objects.equals(key, "name")) {
                value = name;
            }
            urlBuilder.addQuery(key, value);
        }
        String url = urlBuilder.build();

        return url;
    }


}
